// 音频播放组件对象
let innerAudioContext = null;

// 初始化音频播放组件
const initAudioContext = () => {
	return uni.createInnerAudioContext();
}

// 播放音频
const playAudio = src => {
	if (!innerAudioContext) {
		innerAudioContext = initAudioContext();
	}
	innerAudioContext.src = src;
	innerAudioContext.play();
}

// 暂停音频
const pauseAudio = () => {
	if (innerAudioContext) {
		innerAudioContext.pause();
	}
}

// 停止音频
const stopAudio = () => {
	if (innerAudioContext) {
		innerAudioContext.stop();
	}
}

// 播放扫码成功音频
const playScanSuccess = () => {
	playAudio('/static/music/scan-success.mp3');
}

// 播放扫码失败音频
const playScanFail = () => {
	playAudio('/static/music/scan-fail.mp3');
}

export default {
	playScanSuccess,
	playScanFail,
	pauseAudio,
	stopAudio
}
